package com.zx.test;

import com.zx.app.Appconfig;
import com.zx.service.IndexService;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author zx
 * @version 1.0
 * @date 1/11/2021 上午 10:41
 * @Description
 */
public class test {
	public static void main(String[] args) {
		AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(Appconfig.class);
		ac.scan("com.zx");
		ac.register(Appconfig.class);

		/**
		 * 代码形式构建bean
		 */
		GenericBeanDefinition genericBeanDefinition =
				new GenericBeanDefinition();
		genericBeanDefinition.setBeanClass(IndexService.class);
		genericBeanDefinition.setScope("singleton");
		ac.registerBeanDefinition("xx",genericBeanDefinition);
		ac.refresh();

		BeanDefinition beanDefinition = ac.getBeanDefinition("xx");
		System.out.println(beanDefinition);

		IndexService indexService = ac.getBean(IndexService.class);
	}
}
